package com.handpay.zztong.hp.accountcenter.activity;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;

import com.handpay.zztong.hp.R;
import com.handpay.zztong.hp.base.activity.ZZTongActivity;
import com.handpay.zztong.hp.bean.ActionBar;
import com.handpay.zztong.hp.protocol.CardProtocolKey;
import com.handpay.zztong.hp.swiper.SwiperUtils;
import com.handpay.zztong.hp.utils.AccountUtils;
import com.handpay.zztong.hp.utils.AccountUtils.AccountStatus;

/**
 * 资质上传成功界面
 */
public class BaseInfoUploadSuccessActivity extends ZZTongActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        this.setContentView(R.layout.activity_base_info_upload_success);
        super.onCreate(savedInstanceState);

        // 提交成功后，将状态设置为审核中
        AccountUtils.setAccountStatus(this, AccountStatus.CHECKING);
        this.findViewById(R.id.btn_trans).setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                doGoToReceivable();
            }
        });
    }

    @Override
    public ActionBar getActivityActionBar() {
        //leftBar goBack();
        return new ActionBar(this.getString(R.string.upload_success));
    }

    @Override
    protected void onStart() {
        super.onStart();
        String failDes = AccountUtils.getAccountFailDes(this);
        if (TextUtils.isEmpty(failDes)) {
            //直接绑定该刷卡器
            String csn = getIntent().getStringExtra(CardProtocolKey.CSN_KEY);
            if (!TextUtils.isEmpty(csn)) {
                requestBindSwiper(csn);
                getIntent().putExtra(CardProtocolKey.CSN_KEY, "");
            } else {
                if (SwiperUtils.isSwiperConnected() && SwiperUtils.isSwiperOK()) {
                    getCsnStatusIfReady();
                }
            }
        }
    }

    private void doGoToReceivable() {
        this.onTransferTab(null);
    }

    // 禁用掉返回按钮
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            doGoToReceivable();
            return true;
        } else {
            return super.onKeyDown(keyCode, event);
        }
    }

//    public void goToMainActivity(String tag) {
//        Intent t = new Intent(this, MainActivity.class);
//        t.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
//        t.putExtra(FRAGMENTFLAG, tag);
//        this.startActivity(t);
//    }


    @Override
    protected boolean isShownTabs() {
        return false;
    }


}
